﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Security;

namespace GameSchool.Models.OnTheFlyModels
{
    /// <summary>
    /// Person Extra geymir þær upplýsingar sem þarf til að skoða stöðu notenda. 
    /// Vegna tengsla við asp.net register/member klasa.
    /// </summary>  
    
	[NotMapped]
    public class PersonExtra
    {
        public PersonExtra(Person basePerson)
        {
            this.Person = basePerson;
            this.IsAdmin = Roles.IsUserInRole(basePerson.Username, "Administrators");
            this.IsStudent = Roles.IsUserInRole(basePerson.Username, "Students");
            this.IsTeacher = Roles.IsUserInRole(basePerson.Username, "Teachers");
        }
        public int PersonId 
        {
            get 
            {
                return this.Person.PersonId;
            }
        }

        public void SaveRoles()
        {
            if (this.IsAdmin)
            {
                Roles.AddUserToRole(this.Person.Username, "Administrators");
            }
            else
            {
                Roles.RemoveUserFromRole(this.Person.Username, "Administrators");
            }

            if (this.IsTeacher)
            {
                Roles.AddUserToRole(this.Person.Username, "Teachers");
            }
            else
            {
                Roles.RemoveUserFromRole(this.Person.Username, "Teachers");
            }

            if (this.IsStudent)
            {
                Roles.AddUserToRole(this.Person.Username, "Students");
            }
            else
            {
                Roles.RemoveUserFromRole(this.Person.Username, "Students");
            }
        }

        public Person Person { get; set; }
        public bool IsAdmin { get; set; }        
        public bool IsTeacher { get; set; }        
        public bool IsStudent { get; set; }
    }
}
